//
// Created by Administrator on 2016/8/31.
//

#include "Object.h"
using namespace glm;
using namespace ZainGL;

void Object::translate(vec3 vec3Length) {
    mTransform = glm::translate(mat4(), vec3Length) * mTransform;
}

vec3 Object::getForward() {
    return mTransform[2];
}

vec3 Object::getUp() {
    return mTransform[1];
}

vec3 Object::getRight() {
    return mTransform[0];
}

vec3 Object::getPosition() {
    return mTransform[3];
}

void Object::setPosition(const vec3 &position) {
    mTransform[3] = vec4(position, 1.0f);
}

const mat4 Object::getTransform() const {
    return mTransform;
}

void Object::setTransform(const mat4 &transform) {
    mTransform = transform;
}

const std::vector<Object *> &Object::getMInstances() const {
    return mInstances;
}

void Object::setMInstances(const std::vector<Object *> &mInstances) {
    Object::mInstances = mInstances;
}

void Object::rotate(GLfloat radian, glm::vec3 vec3Factor, vec3 *pivot) {
    mat4 transform;
    if (pivot != nullptr) {
        transform = glm::translate(transform, *pivot);
        transform = glm::rotate(transform, radian, vec3Factor);
        transform = glm::translate(transform, -*pivot);
    } else {
        transform = glm::rotate(transform, radian, vec3Factor);
    }
    mTransform = transform * mTransform;
}
